﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WPF_Print
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {


        private int codex = 10;
        private int codey = 10;
        private int codef = 12;

        private int dex = 300;
        private int dey = 10;
        private int def = 12;
        public MainWindow()
        {
            InitializeComponent();
            this.Topmost = true;
            codex = Convert.ToInt32(txtCodex.Text);
            codey = Convert.ToInt32(txtCodey.Text);
            codef = Convert.ToInt32(txtCodeFont.Text);

            dex = Convert.ToInt32(txtDescx.Text);
            dey = Convert.ToInt32(txtDescy.Text);
            def = Convert.ToInt32(txtDescFont.Text);
        }

        private void btnTestPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            pd.Print();
        }

        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            int codex = Convert.ToInt32(txtCodex.Text);
            int codey = Convert.ToInt32(txtCodey.Text);
            int codefont = Convert.ToInt32(txtCodeFont.Text);

            int descx = Convert.ToInt32(txtDescx.Text);
            int descy = Convert.ToInt32(txtDescy.Text);
            int descfont = Convert.ToInt32(txtDescFont.Text);

            ev.Graphics.DrawString("Test_Code", new Font(new System.Drawing.FontFamily("黑体"), codefont), System.Drawing.Brushes.Black, codex, codey);
            ev.Graphics.DrawString("Test_Desc", new Font(new System.Drawing.FontFamily("黑体"), descfont), System.Drawing.Brushes.Black, descx, descy);
        }

        private void btnTestPrintDoc_Click(object sender, RoutedEventArgs e)
        {
           
            PrintDialog pdlg = new PrintDialog();
            pdlg.PrintVisual(printArea, "Order Print");
            
            //Dispatcher.BeginInvoke(new DoPrintMethod(DoPrint), DispatcherPriority.ApplicationIdle, pdlg, ((IDocumentPaginatorSource)doc).DocumentPaginator);
            //m_timerToEnableButton = new Timer(TestTimerCallback, null, 3000, Timeout.Infinite);
        }

        

        private void txtCodex_TextChanged(object sender, TextChangedEventArgs e)
        {
            codex= Convert.ToInt32(txtCodex.Text);
            txtCode.Margin = new Thickness(codex, codey, 0, 0);
            
        }

        private void txtCodey_TextChanged(object sender, TextChangedEventArgs e)
        {
            codey = Convert.ToInt32(txtCodey.Text);
            txtCode.Margin = new Thickness(codex, codey, 0, 0);
        }

        private void txtCodeFont_TextChanged(object sender, TextChangedEventArgs e)
        {
            txtCode.FontSize = Convert.ToDouble(txtCodeFont.Text);
        }

        private void txtDescx_TextChanged(object sender, TextChangedEventArgs e)
        {
            dex = Convert.ToInt32(txtDescx.Text);
            txtDesc.Margin = new Thickness(dex, dey, 0, 0);
        }

        private void txtDescy_TextChanged(object sender, TextChangedEventArgs e)
        {
            dey = Convert.ToInt32(txtDescy.Text);
            txtDesc.Margin = new Thickness(dex, dey, 0, 0);
        }

        private void txtDescFont_TextChanged(object sender, TextChangedEventArgs e)
        {
            txtDesc.FontSize = Convert.ToDouble(txtDescFont.Text);
        }
    }

    public class EntityDto
    {
        public string ProdCode { get; set; }

        public string ProdDesc { get; set; }
    }
}
